{% extends 'admin/admin_base.html' %}

{% block content %}
<div class="container mt-4">
    <nav aria-label="breadcrumb">
        <ol class="breadcrumb">
            <li class="breadcrumb-item"><a href="{{ url_for('admin.test_management') }}">测试管理</a></li>
            <li class="breadcrumb-item active">试卷详情</li>
        </ol>
    </nav>

    <div class="card mb-4">
        <div class="card-header bg-primary text-white">
            <h4 class="mb-0">试卷详情</h4>
        </div>
        <div class="card-body">
            <div class="row mb-4">
                <div class="col-md-6">
                    <h5 class="border-bottom pb-2">试卷信息</h5>
                    <p><strong>试卷名称：</strong>{{ exam.name }}</p>
                    <p><strong>题目数量：</strong>{{ exam.questions|length }}</p>
                    <p><strong>难度等级：</strong>{{ exam.difficulty }}</p>
                </div>
                <div class="col-md-6">
                    <h5 class="border-bottom pb-2">考生信息</h5>
                    <p><strong>学生姓名：</strong>{{ submission.student_name }}</p>
                    <p><strong>所属学校：</strong>{{ submission.school }}</p>
                    <p><strong>提交时间：</strong>{{ submission.submit_time.strftime('%Y-%m-%d %H:%M:%S') }}</p>
                    <p><strong>得分：</strong>{{ submission.score }}</p>
                </div>
            </div>

            <div class="answers-section">
                <h5 class="border-bottom pb-2 mb-4">答题详情</h5>
                {% for question, answer in questions_with_answers %}
                <div class="card mb-3">
                    <div class="card-header {% if answer.is_correct %}bg-success{% else %}bg-danger{% endif %} text-white">
                        <div class="d-flex justify-content-between align-items-center">
                            <span>第 {{ loop.index }} 题 ({{ '单选题' if question.type == 'single' else '多选题' if question.type == 'multiple' else '判断题' }})</span>
                            <span>{% if answer.is_correct %}答对{% else %}答错{% endif %}</span>
                        </div>
                    </div>
                    <div class="card-body">
                        <h6 class="card-title">{{ question.title }}</h6>
                        <div class="options mt-3">
                            {% if question.type == 'boolean' %}
                                <p><strong>正确答案：</strong>{{ '正确' if question.correct_answers[0] else '错误' }}</p>
                                <p><strong>学生答案：</strong>{{ '正确' if answer.user_answer else '错误' }}</p>
                            {% elif question.type == 'single' %}
                                <p><strong>选项：</strong></p>
                                <ul class="list-group">
                                    {% for option in question.options %}
                                    <li class="list-group-item {% if loop.index0 == question.correct_answers[0] %}list-group-item-success{% endif %} 
                                                             {% if loop.index0 == answer.user_answer %}list-group-item-info{% endif %}">
                                        {{ option }}
                                        {% if loop.index0 == question.correct_answers[0] %}
                                            <span class="badge bg-success float-end">正确答案</span>
                                        {% endif %}
                                        {% if loop.index0 == answer.user_answer %}
                                            <span class="badge bg-info float-end">学生答案</span>
                                        {% endif %}
                                    </li>
                                    {% endfor %}
                                </ul>
                            {% else %}
                                <p><strong>选项：</strong></p>
                                <ul class="list-group">
                                    {% for option in question.options %}
                                    <li class="list-group-item {% if loop.index0 in question.correct_answers %}list-group-item-success{% endif %} 
                                                             {% if answer.user_answer and loop.index0 in answer.user_answer %}list-group-item-info{% endif %}">
                                        {{ option }}
                                        {% if loop.index0 in question.correct_answers %}
                                            <span class="badge bg-success float-end">正确答案</span>
                                        {% endif %}
                                        {% if answer.user_answer and loop.index0 in answer.user_answer %}
                                            <span class="badge bg-info float-end">学生答案</span>
                                        {% endif %}
                                    </li>
                                    {% endfor %}
                                </ul>
                            {% endif %}
                        </div>
                    </div>
                </div>
                {% endfor %}
            </div>
        </div>
    </div>
</div>
{% endblock %}
